package wish.regularExpression;

import java.util.ArrayList;
import java.util.List;

public class SingleElement extends RegularExpressionElement {

	private String element;
	private List<RegularExpressionElement> list;
	
	public SingleElement(String element){
		this.element = element;
		list = new ArrayList<RegularExpressionElement>();
		list.add(this);
	}
	
	@Override
	public boolean matches(RegularExpressionElement regExpele) {
		
		for (RegularExpressionElement regExp : regExpele.getMachingElements()) {
			
			if (this.equals(regExp)){
				return true;
			}
			
		}
		
		return false;
	}

	public String toString(){
		return element;
	}

	@Override
	public List<RegularExpressionElement> getMachingElements() {
		
		return list;
		
	}

	@Override
	public boolean equals(Object obj) {
		return element.equals(obj.toString());
	}

	@Override
	protected RegularExpressionElement expandWithMatchingRegularExpression(
			RegularExpressionElement regExp) {
		
		if (regExp.isMultipleMatch()){
			return regExp;
		}
		return this;
	}
}
